package com.example.ten.Utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBOpenHelper extends SQLiteOpenHelper {

    private String CREATE_USER = "create table user(_id integer primary key autoincrement,name varchar(20)," +
            "password text)";

    private String CREATE_TEMP_USER = "alter table user rename to _temp_user";//把表名改为临时表名

    private String INSERT_DATA = "insert into user select * from _temp_user";

    private String DROP_USER = "drop table _temp_user";
    private String INSERT_USER="alter table user add column sex text";

    public DBOpenHelper(@Nullable Context context) {
        super(context,ContentUtils.DB_NAME,null,ContentUtils.DB_VERSION_CODE);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql1 = "create table moivetb(id integer primary key,title varchar(40),author varchar(40),authorbrief varchar(40)," +
                "times integer,text1 text,text2 text,text3 text,text4 text,text5 text,image1 text,image2 text," +
                "image3 text,image4 text,image5 text,imageforplay text,urlforplay text,titleforplay varchar(40)," +
                "realtitle varchar(40),publishtime varchar(40),type integer not null)";

        String sql2 = "create table arttb(id integer primary key,title varchar(40),author varchar(40),authorbrief varchar(40)," +
                "times integer,summary text,text1 text,image text,publishtime varchar(40),type integer not null)";

        String sql3 = "create table imgtb(id integer primary key,title varchar(40),author varchar(40),authorbrief varchar(40)," +
                "text1 text,image1 text,text2 varchar(40),times integer,publishtime varchar(40),type integer not null)";

        String sql4 = "create table favtb(id integer primary key autoincrement,content_id integer not null, type integer not null)";
        db.execSQL(sql1);
        db.execSQL(sql2);
        db.execSQL(sql3);
        db.execSQL(sql4);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
